﻿Imports System.Data.OleDb

Public Class AddResearch
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_addSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_addSubmit.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"
        If fu_picture.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("Research_Pic") & "/" & newFileName
            fu_picture.SaveAs(picLocationOnServerHardDisk)
        End If
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("FinalConnectionString").ConnectionString)
        Dim sql As String = "INSERT INTO Researches (Title,AddedBy,FieldOfStudy,University,FirstPagePicture,Contact,Description,Rating,Link) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim cmdDB As OleDbCommand = New OleDbCommand(sql, conn)

        cmdDB.Parameters.AddWithValue("@f1", tb_title.Text)
        cmdDB.Parameters.AddWithValue("@f2", User.Identity.Name)
        cmdDB.Parameters.AddWithValue("@f3", tb_category.Text)
        cmdDB.Parameters.AddWithValue("@f4", tb_university.Text)
        cmdDB.Parameters.AddWithValue("@f5", "Research_Pic/" & newFileName)
        cmdDB.Parameters.AddWithValue("@f6", tb_emailAddress.Text)
        cmdDB.Parameters.AddWithValue("@f7", tb_note.Text)
        cmdDB.Parameters.AddWithValue("@f8", rbl_rating.SelectedValue)
        cmdDB.Parameters.AddWithValue("@f9", tb_link.Text)
        conn.Open()
        cmdDB.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("ResearchListDetails.aspx?ID=" & Request.Params("ID"))
    End Sub
End Class